package com.ssm.juc.executors;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleThreadPoolTest {

    public static void main(String[] args) {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(5);
        Task task100 = new Task("task_100");
        System.out.println("Created: " + task100.getName());
        executor.schedule(task100, 2, TimeUnit.SECONDS);
        // 任务 + 延迟
        executor.scheduleWithFixedDelay(task100, 0,2, TimeUnit.SECONDS);
        // 任务 + 延迟取最大值
        executor.scheduleAtFixedRate(task100, 0,2, TimeUnit.SECONDS);
        System.out.println("当前线程名:" + Thread.currentThread().getName());

    }
}
